package com.lanjiu.lib.imclient.dto.notify;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.lib.imclient.dto.GroupMemberDto;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.ims.IMSContacts;

/**
 * @description: 群组通知
 * @author: Panwei
 * @date: 2019/11/14 21:47
 */
public class GroupNotifyDto extends Dto {

    // 类型(申请/邀请)
    private int type;

    // 申请状态(申请/拒绝/同意)
    private int status;

    // 群成员实体
    private GroupMemberDto groupMember;

    // 留言
    private String leaveMessage;

    public GroupNotifyDto() {
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public GroupMemberDto getGroupMember() {
        return groupMember;
    }

    public void setGroupMember(GroupMemberDto groupMember) {
        this.groupMember = groupMember;
    }

    public String getLeaveMessage() {
        return leaveMessage;
    }

    public void setLeaveMessage(String leaveMessage) {
        this.leaveMessage = leaveMessage;
    }

    public GroupNotifyDto(BusinessProtocolEntities.TouristsGroupNotify groupNotify) {
        this.type = groupNotify.getType();
        this.status = groupNotify.getStatus();
        this.groupMember = new GroupMemberDto(groupNotify.getGroupMember());
        this.leaveMessage = groupNotify.getLeaveMessage();
    }

    public GroupNotifyDto(BusinessProtocolEntities.RegisteredGroupNotify groupNotify) {
        this.type = groupNotify.getType();
        this.status = groupNotify.getStatus();
        this.groupMember = new GroupMemberDto(groupNotify.getGroupMember());
        this.leaveMessage = groupNotify.getLeaveMessage();
    }

    @Override
    public Object toProtobuf() {
        if (IMSContacts.UserType.REGISTERED_USER.equals(groupMember.getCurrentUserType())) {
            BusinessProtocolEntities.RegisteredGroupNotify.Builder builder = BusinessProtocolEntities.RegisteredGroupNotify.newBuilder();
            builder.setType(type);
            builder.setStatus(status);
            if (null != groupMember)
                builder.setGroupMember((BusinessProtocolEntities.RegisteredGroupMember) groupMember.toProtobuf());
            if (null != leaveMessage) builder.setLeaveMessage(leaveMessage);
            return builder.build();
        } else {
            BusinessProtocolEntities.TouristsGroupNotify.Builder builder = BusinessProtocolEntities.TouristsGroupNotify.newBuilder();
            builder.setType(type);
            builder.setStatus(status);
            if (null != groupMember)
                builder.setGroupMember((BusinessProtocolEntities.TouristsGroupMember) groupMember.toProtobuf());
            if (null != leaveMessage) builder.setLeaveMessage(leaveMessage);
            return builder.build();
        }
    }
}
